package cn.ifly.controller;

import cn.ifly.commen.ResultUtil;
import cn.ifly.model.ResponseBody;
import cn.ifly.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 用户控制层
 */
@RestController
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 新增用户
     */
    @RequestMapping(value = "/addUser", produces = "application/json;charset=utf-8")
    public ResponseBody addUser(@RequestBody Map<String, Object> map) {
        userService.addUser(map);
        return new ResultUtil().success("OK");
    }
    /**
     * 根据用户姓名更新用户信息
     */
    @RequestMapping(value = "/updateUser", produces = "application/json;charset=utf-8")
    public ResponseBody updateUser(@RequestBody Map<String, Object> map){
        userService.updateUser(map);
        return new ResultUtil().success("OK");
    }
    /**
     * 根据用户ID更新用户信息
     */
    @RequestMapping(value = "/updateUserById", produces = "application/json;charset=utf-8")
    public ResponseBody updateUserById(@RequestBody Map<String, Object> map){
        userService.updateUserById(map);
        return new ResultUtil().success("OK");
    }
    /**
     * 根据用户姓名删除用户
     */
    @RequestMapping(value = "/delUser", produces = "application/json;charset=utf-8")
    public ResponseBody delUser(@RequestBody Map<String, Object> map){
        userService.delUser(map);
        return new ResultUtil().success("OK");
    }

    /**
     * 查询用户列表
     */
    @RequestMapping(value = "/queryUserList", produces = "application/json;charset=utf-8")
    public ResponseBody queryUserList(@RequestBody Map<String, Object> map){
        Map<String, Object> resultMap = userService.queryUserList(map);
        return new ResultUtil().success(resultMap);
    }

    /**
     * 修改用户密码
     */
    @RequestMapping(value = "/updateUserPass", produces = "application/json;charset=utf-8")
    public ResponseBody updateUserPass(@RequestBody Map<String, Object> map){
        userService.updateUserPass(map);
        return new ResultUtil().success("OK");
    }



}

